Skip to content

fix(event_handler): prioritize static over dynamic route to prevent order of route registration mismatch #2458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 14, 2023

Conversation

rubenfonseca
Copy link
Contributor

Issue number: #2439

Summary

Changes

Please provide a summary of what's being changed

This PR changes the priority of route matching, so that the most specific route is matched first.

User experience

Please share what the user experience looks like before and after this change

Take into consideration the following code:

from aws_lambda_powertools.event_handler import APIGatewayRestResolver

app = APIGatewayRestResolver()


@app.get("/studies/<studyid>")
def get_study(studyid):
    return "get_study"


@app.get("/studies/fetch")
def fetch_studies():
    return "fetch_studies"


def handler(event, context):
    return app.resolve(event, context)

Before this change, /studies/fetch would match the first route, because it's a prefix of /studies/<studyid>. After this change, the most specific route is matched first, so /studies/fetch will match the second route.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 14, 2023
@github-actions github-actions bot added the bug Something isn't working label Jun 14, 2023
@rubenfonseca rubenfonseca marked this pull request as ready for review June 14, 2023 15:12
@rubenfonseca rubenfonseca requested a review from a team as a code owner June 14, 2023 15:12
@rubenfonseca rubenfonseca requested review from leandrodamascena and removed request for a team June 14, 2023 15:12
@rubenfonseca rubenfonseca linked an issue Jun 14, 2023 that may be closed by this pull request
@rubenfonseca
Copy link
Contributor Author

As the failing test is showing, it seems we might be breaking some existing behavior. Let me look into this deeper.

@rubenfonseca
Copy link
Contributor Author

Ok, tried a new approach which changes some private properties, which I think it's ok.

@heitorlessa
Copy link
Contributor

looking 👀

@heitorlessa heitorlessa changed the title fix(event_handler): prioritize full route matching fix(event_handler): prioritize static over dynamic route to prevent order of route registration mismatch Jun 14, 2023
@heitorlessa heitorlessa removed the request for review from leandrodamascena June 14, 2023 16:58
@heitorlessa
Copy link
Contributor

all good here provided CI pass now. Leaving to @leandrodamascena to merge as he expressed he wanted to learn about the fix.

@heitorlessa
Copy link
Contributor

heitorlessa commented Jun 14, 2023

Leandro just shared he's learned it 2 hours ago. GH Actions seems to be experiencing operational issues... :/, so I'll merge it on the basis that make pr worked locally.

We'll know either way once they resolve capacity management issues.

GREAT work @rubenfonseca investigating and fixing it.

@heitorlessa heitorlessa merged commit 62a123c into develop Jun 14, 2023
@heitorlessa heitorlessa deleted the rf/fix-apigateway-order branch June 14, 2023 17:04
sthulb pushed a commit that referenced this pull request Jun 19, 2023
…rder of route registration mismatch (#2458)

Co-authored-by: heitorlessa <[email protected]>
rafaelgsr pushed a commit to rafaelgsr/aws-lambda-powertools-python that referenced this pull request Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_handlers size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

APIGatewayRestResolver route matching order
2 participants